package com.qingke.notlonely.command.system;

import com.qingke.notlonely.bean.User;
import com.qingke.notlonely.bean.Yue;
import com.qingke.notlonely.command.SystemCommand;
import com.qingke.notlonely.util.NLConsole;

public class AddYue extends SystemCommand{

	@Override
	public void execute() {
		int inviterId=NLConsole.getInt("inviter id:");
		boolean isExist=dao.isUserExistById(inviterId);
		if(!isExist){
			NLConsole.println("the inviter is not exist.");
			return ;
		}
		int inviteeId=NLConsole.getInt("invitee id:");
		isExist=dao.isUserExistById(inviteeId);
		if(!isExist){
			NLConsole.println("the invitee is not exist.");
			return ;
		}
		boolean isAccepted;
		while(true){
			String str=NLConsole.promptNotEmpty("is accepted(y,n):").trim();
			if("y".equalsIgnoreCase(str))
				isAccepted=true;
			else if("n".equalsIgnoreCase(str))
				isAccepted=false;
			else{
				NLConsole.println("err input");
				continue;
			}
			break;
		}
		User inviter=dao.selectUserById(inviterId);
		User invitee=dao.selectUserById(inviteeId);
		Yue yue=new Yue();
		yue.setInviter(inviter);
		yue.setInvitee(invitee);
		yue.setAccepted(isAccepted);
		
		boolean isSuccess=dao.save(yue);
		if(isSuccess)
			NLConsole.println("add yue success");
		else
			NLConsole.println("add yue failed");
	}

}
